package com.example.mybatisplus.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.mybatisplus.mapper.FirstAppointmentMapper;
import com.example.mybatisplus.model.domain.DutyTime;
import com.example.mybatisplus.model.domain.FirstAppointment;
import com.example.mybatisplus.model.dto.PageDTO;
import com.example.mybatisplus.service.DutyTimeService;
import com.example.mybatisplus.service.FirstAppointmentService;

/**
 * <p>
 * 学生初访预约信息 服务实现类
 * </p>
 *
 * @author cft
 * @since 2022-06-24
 */
@Service
public class FirstAppointmentServiceImpl extends ServiceImpl<FirstAppointmentMapper, FirstAppointment> implements FirstAppointmentService {

    @Autowired
	FirstAppointmentMapper firstAppointmentMapper;
	
	/* 
	 * author:tqq
	 * function:根据已经登录的学生查询初访预约信息
	 */
    @Override
	public List<FirstAppointment> getBystuId(Long stuid) {
		QueryWrapper<FirstAppointment> wrapper = new QueryWrapper<>();
		wrapper.eq("stu_id", stuid);
		List<FirstAppointment> list = firstAppointmentMapper.selectList(wrapper);
		return list;
	}


	/* 
	 * author:cft
	 * function:查询所有待处理的学生初访预约信息
	 */
	@Override
	public Page<FirstAppointment> getAllWaitedFirstApply(PageDTO pageDTO, FirstAppointment firstAppointment) {
		Page<FirstAppointment> page = new Page<>(pageDTO.getPageNo(), pageDTO.getPageSize());
		QueryWrapper<FirstAppointment> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("apo_status", "已申请");

		page = super.page(page, queryWrapper);
		return page;

	}


	/* 
	 * author:tqq
	 * function:撤回初访预约
	 */
    @Override
    public void updatewithCurrentUser(FirstAppointment firstAppointment) {
        firstAppointment.setApoStatus("已撤回").setFApoResult("已撤回");
        firstAppointmentMapper.updateById(firstAppointment);
    }

	/*
	 * author:tqq
	 * function:根据学生id查询初访预约信息
	 */
	@Override
	public FirstAppointment getByoneStuId(Long conStuId) {
		QueryWrapper<FirstAppointment> wrapper = new QueryWrapper<>();
		wrapper.eq("stu_id",conStuId);
		return this.getOne(wrapper);
	}


	/*
	 * author:cft
	 * function:获得学生选择的初访时间
	 */
	@Autowired
	DutyTimeService dutyTimeService;
	@Override
	public String[] getStuApoTime(String[] time) {
		DutyTime dutyTime=new DutyTime();
		String[] result = new String[3];
		for (int i = 0; i < time.length; i++) {
			dutyTime = dutyTimeService.getById(Integer.parseInt(time[i]));
			result[i] = dutyTime.getDutyDate() + "  " + dutyTime.getDutyStartTime() + "--" + dutyTime.getDutyStartTime();
		}
		return result;
	}
}
